package com.zxkj.commonpatrol.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.base.BaseViewModel;
import com.czy.basecommon.utils.base.StateLiveData;
import com.zxkj.commonpatrol.model.entity.HistoryQuestEntity;
import com.zxkj.commonpatrol.model.post.PostLogInfo;
import com.zxkj.commonpatrol.model.response.DevEvtQuestPatrolHistoryResponse;
import com.zxkj.commonpatrol.model.response.LogBean;
import com.zxkj.commonpatrol.repoisity.AddCheckPointRepoisity;
import com.zxkj.commonpatrol.repoisity.QuestDetailRepoisity;

import java.util.ArrayList;
import java.util.List;

public class QuestDetailViewModel extends BaseViewModel<QuestDetailRepoisity> {

    public StateLiveData<List<HistoryQuestEntity>> data=new StateLiveData<>();
    public ObservableField<String>Tips=new ObservableField<>("");

    public StateLiveData< List<DevEvtQuestPatrolHistoryResponse.DevEvtQuestHis>> mHistoryData=new StateLiveData<>();
    public StateLiveData< DevEvtQuestPatrolHistoryResponse> mData=new StateLiveData<>();

    public StateLiveData<Object>FixException=new StateLiveData<>();
    public StateLiveData<String>UpLoad=new StateLiveData<>();
    public QuestDetailViewModel(@NonNull Application application) {
        super(application);
    }

    public  void  getData(){
        mRepository.getData(new BaseRepository.MyBaseDataCallBack<List<HistoryQuestEntity>>() {
            @Override
            public void onDataSuccessCallBack(List<HistoryQuestEntity> historyQuestEntities) {
                data.postSuccess(historyQuestEntities);
            }

            @Override
            public void onDataFailCallBack(List<HistoryQuestEntity> historyQuestEntities, List<HistoryQuestEntity> t1) {

            }
        });
    }


    public void getDevQuestPatrolHisoty(String RouteInspectNo, String PointNo, String DeviceNo,String QuestsNo, String QuestNo,int Type) {
        mRepository.getDevQuestPatrolHisoty(RouteInspectNo, PointNo, DeviceNo, QuestsNo,QuestNo,Type, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                DevEvtQuestPatrolHistoryResponse devEvtQuestPatrolHistoryResponse = (DevEvtQuestPatrolHistoryResponse) o;
                if(devEvtQuestPatrolHistoryResponse !=null){
                    mData.postSuccess(devEvtQuestPatrolHistoryResponse);
                    List<DevEvtQuestPatrolHistoryResponse.DevEvtQuestHis> devQuests = devEvtQuestPatrolHistoryResponse.getDevQuests();
                    if (devEvtQuestPatrolHistoryResponse.QuestTips!=null){
                        Tips.set(devEvtQuestPatrolHistoryResponse.QuestTips);
                    }
                    if (devQuests==null){
                        devQuests=new ArrayList<>();

                    }
                    mHistoryData.postSuccess(devQuests);
                }
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                mHistoryData.postFailure(404,(String)t1);
            }
        });

    }

    public void getFixException(String logId){
        mRepository.getFixException(logId, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                FixException.postSuccess(o);
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                FixException.postFailure(404,(String)t1);
            }
        });
    }

    /**
     * 上传巡检记录
     * @param postLogInfo
     */
    public void uploadLog(PostLogInfo postLogInfo){
        mRepository.uploadLog(postLogInfo, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                String logBean =(String)o;
                UpLoad.postSuccess(logBean);
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                UpLoad.postFailure(404,(String)t1);
            }
        });
    }

}
